<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - example_args.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2008  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='tester.h.html'>tester.h</a>"

<font color='#009900'>// This is called an unnamed-namespace and it has the effect of making everything 
</font><font color='#009900'>// inside this file "private" so that everything you declare will have static linkage.  
</font><font color='#009900'>// Thus we won't have any multiply defined symbol errors coming out of the linker when 
</font><font color='#009900'>// we try to compile the test suite.
</font><font color='#0000FF'>namespace</font>  
<b>{</b>
    <font color='#009900'>// Declare the logger we will use in this test.  The name of the logger 
</font>    <font color='#009900'>// should start with "test."
</font>    dlib::logger <b><a name='dlog'></a>dlog</b><font face='Lucida Console'>(</font>"<font color='#CC0000'>test.example_args</font>"<font face='Lucida Console'>)</font>;

    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> test;

    <font color='#0000FF'>class</font> <b><a name='example_args_tester'></a>example_args_tester</b> : <font color='#0000FF'>public</font> tester
    <b>{</b>
        <font color='#009900'>/*!
            WHAT THIS OBJECT REPRESENTS
                This object represents a unit test.  When it is constructed
                it adds itself into the testing framework.
                
                This particular test requires the user to supply a command line 
                argument when they run it.
        !*/</font>
    <font color='#0000FF'>public</font>:
        <b><a name='example_args_tester'></a>example_args_tester</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> :
            tester <font face='Lucida Console'>(</font>
                "<font color='#CC0000'>test_example_args</font>",                <font color='#009900'>// the command line argument name for this test
</font>                "<font color='#CC0000'>Run example tests with argument.</font>", <font color='#009900'>// the command line argument description
</font>                <font color='#979000'>1</font>                                   <font color='#009900'>// the number of command line arguments for this test
</font>            <font face='Lucida Console'>)</font>
        <b>{</b><b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='perform_test'></a>perform_test</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> arg
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// This message gets logged to the file debug.txt if the user has enabled logging by
</font>            <font color='#009900'>// supplying the -d option on the command line (and they haven't set the logging level
</font>            <font color='#009900'>// to something higher than LINFO).
</font>            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> dlib::LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>some message you want to log</font>";
            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> dlib::LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>the argument passed to this test was </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> arg;

            <font color='#009900'>// This test is considered a success if this function doesn't throw an exception.  
</font>            <font color='#009900'>// So we can use the DLIB_TEST_MSG macro to perform our tests since it throws an 
</font>            <font color='#009900'>// exception containing a message if its first argument is false.  
</font>
            <font color='#009900'>// make sure 3 is bigger than 2
</font>            <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#979000'>3</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>2</font>,"<font color='#CC0000'>This message prints if your compiler doesn't know 3 is bigger than 2</font>"<font face='Lucida Console'>)</font>;

            <font color='#009900'>// make sure 5 is not equal to 9
</font>            <font color='#BB00BB'>DLIB_TEST_MSG</font><font face='Lucida Console'>(</font><font color='#979000'>5</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>9</font>,"<font color='#CC0000'>This message prints if your compiler thinks 5 is the same as 9</font>"<font face='Lucida Console'>)</font>;

            <font color='#009900'>// If your test takes a long time to run you can also call print_spinner() 
</font>            <font color='#009900'>// periodically.  This will cause a spinning / character to display on the
</font>            <font color='#009900'>// console to indicate to the user that your test is still running (rather
</font>            <font color='#009900'>// than hung) 
</font>            <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <b>}</b>;

    <font color='#009900'>// Create an instance of this object.  Doing this causes this test
</font>    <font color='#009900'>// to be automatically inserted into the testing framework whenever this cpp file
</font>    <font color='#009900'>// is linked into the project.  Note that since we are inside an unnamed-namespace 
</font>    <font color='#009900'>// we won't get any linker errors about the symbol a being defined multiple times. 
</font>    example_args_tester a;
<b>}</b>




</pre></body></html>